﻿/**
* @file port.h
* @brief this is a brief description
* @details this is the detail description.
* @author fulong 
* @data 2014/10/23
* @version 1.0
* @par Copyright (c):
* @par First build
*     version: fulong 
*     data: 2014/10/23
*/
#ifndef __PORT_H__
#define __PORT_H__
#include "../hal_include/hal_types.h"
//about i2c
/*!< set what the sda of i2c port is */
#define I2C_SDA_PORT(portdata)  p3_4=(portdata)
#define i2c_sda_output() set_output(3,4)
#define i2c_sda_input() set_input(3,4)
#define READ_I2C_SDA_PORT() p3_4

/*!< set what the scl of i2c port is */
#define I2C_SCL_PORT(portdata) p3_5=(portdata)
#define i2c_sck_output() set_output(3,5)
//about output
#define OUTPUT_CTRL_ON() p9_0=1
#define set_output_led_ctrl_output() set_output(9,0)

/*!< test output port*/
//#define OUTPUT_TEST

#define OUT11(odata) p8_3=(odata)
#define OUT10(odata) p8_4=(odata)
#define OUT7(odata) p8_6=(odata)
#define OUT6(odata) p8_7=(odata)
#define OUT5(odata) p2_0=(odata)
#define OUT4(odata) p2_3=(odata)
#define OUT3(odata) p2_4=(odata)
#define OUT2(odata) p2_5=(odata)
#define OUT1(odata) p2_6=(odata)
#define OUT0(odata) p2_7=(odata)

#define set_out0_output()  set_output(2,7)
#define set_out1_output()  set_output(2,6)
#define set_out2_output()  set_output(2,5)
#define set_out3_output()  set_output(2,4)
#define set_out4_output()  set_output(2,3)
#define set_out5_output()  set_output(2,0)
#define set_out6_output()  set_output(8,7)
#define set_out7_output()  set_output(8,6)
#define set_out10_output()  set_output(8,4)
#define set_out11_output()  set_output(8,3)
//about input

#define set_in0_input() set_input(6,1)
#define set_in1_input() set_input(6,2)
#define set_in2_input() set_input(0,4)
#define set_in3_input() set_input(0,3)
#define set_in4_input() set_input(0,2)
#define set_in5_input() set_input(0,1)
#define set_in6_input() set_input(0,0)
#define set_in7_input() set_input(7,0)
#define set_in10_input() set_input(7,1)
#define set_in11_input() set_input(7,2)
#define set_in12_input() set_input(7,3)
#define set_in13_input() set_input(7,4)
#define set_in14_input() set_input(7,5)
#define set_in15_input() set_input(7,6)
#define set_in16_input() set_input(3,6)
#define set_in17_input() set_input(3,0)
#define set_in20_input() set_input(3,1)
#define set_in21_input() set_input(6,3)

#define IN0_PIN p6_1
#define IN1_PIN p6_2
#define IN2_PIN p0_4
#define IN3_PIN p0_3
#define IN4_PIN p0_2
#define IN5_PIN p0_1
#define IN6_PIN p0_0
#define IN7_PIN p7_0
#define IN10_PIN p7_1
#define IN11_PIN p7_2
#define IN12_PIN p7_3
#define IN13_PIN p7_4
#define IN14_PIN p7_5
#define IN15_PIN p7_6
#define IN16_PIN p3_6
#define IN17_PIN p3_0
#define IN20_PIN p3_1
#define IN21_PIN p6_3
//about 485
#define CTRL_485()  {set_output(1,6);}
#define CTRL_PORT_485(odata) p1_6=(odata)

//about running led
#define RUN_LED_ON() p4_3=0
#define RUN_LED_OFF() p4_3=1
#define RUN_LED_CTRL() set_output(4, 3);

//about keyboard

#define KEYBOARD_ROW 1
#define KEYBOARD_LINE 3
#define set_keycol1_port_input()      set_input(9,1)
#define set_keycol2_port_input()      set_input(9,2)
#define set_keycol3_port_input()      set_input(9,3)
#define keycol1_in p9_1
#define keycol2_in p9_2
#define keycol3_in p9_3

//about display

#ifdef __SIMPLE_DISPLAY__
    #define LED_B1(value)			p0_5=(value)
    #define set_led_seg1_output() set_output(0, 5);
    #define LED_B2(value)			p0_6=(value)
    #define set_led_seg2_output() set_output(0, 6);
    #define LED_B3(value)			p0_7=(value)
    #define set_led_seg3_output() set_output(0, 7);

    #define	LEDDATAPORT(portdata)		p5=(portdata)
    #define set_led_data_port_output() { \
    set_output(5, 0);\
    set_output(5, 1);\
    set_output(5, 2);\
    set_output(5, 3);\
    set_output(5, 4);\
    set_output(5, 5);\
    set_output(5, 6);\
    set_output(5, 7);\
}
#endif
#endif /* __PORT_H__ */


